import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 10 选 5 组合算法
 */
public class X选YDemo {
    
    public static void main(String[] args) {

        try{


            int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            LinkedList<List<Integer>> combinations = new LinkedList<>();

            selectFive(numbers, 0, new LinkedList<>(), combinations);

            for (List<Integer> combination : combinations) {

                combination.stream().map(s -> s+", ").forEach(System.out::print);

                System.out.println();
            }


        }catch(Exception e){

            e.printStackTrace();
        }
        
    }

    private static void selectFive(int[] numbers, int index, LinkedList<Integer> currentCombination, List<List<Integer>> allCombinations) {
        if (currentCombination.size() == 5) {
            allCombinations.add(new ArrayList<>(currentCombination));
            return;
        }
        if (index == numbers.length) {
            return;
        }
        currentCombination.add(numbers[index]);
        selectFive(numbers, index + 1, currentCombination, allCombinations);
        System.out.println("删除末尾--"+currentCombination.removeLast());
        currentCombination.stream().map(s -> s+", ").forEach(System.out::print);
        System.out.println();
        selectFive(numbers, index + 1, currentCombination, allCombinations);
    }

}
